import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';
const baseUrl = '/sales/api/v1';

const getInitdesc = formatMessage({
    id: 'api.message.getInitdesc',
    defaultMessage: '初始化'
});
const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询'
});
const getProductsDesc = formatMessage({
    id: 'api.message.getProductsDesc',
    defaultMessage: '查询车型'
});
const getProductListDesc = formatMessage({
    id: 'api.message.getProductListDesc',
    defaultMessage: '查询物料组'
});
const getMarketDepartmentDesc = formatMessage({
    id: 'api.message.getMarketDepartmentDesc',
    defaultMessage: '查询大区'
});
const exportDesc = formatMessage({
    id: 'api.exportDesc',
    defaultMessage: '导出'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/saleOrderForecastOrder/init`, null, dto.InitData)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getInitdesc));

// 查询订单列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/saleOrderForecastOrders?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询物料组
export const getProduct = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/products/forSalePlanOrder?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getProductListDesc));
};
// 查询大区
export const getMarketDepartment = condition => {
    const queryString = stringify(condition);
    return request(`${baseUrl}/marketDepartments?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getMarketDepartmentDesc));
};
// 查询车型
export const getProducts = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/products/forSaleOrderForecastOrder?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getProductsDesc));
};
// 导出
export const exports = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/saleOrderForecastOrders/export?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, exportDesc))
        .then(res => res.data);
};
